package cn.kgc.controller;

import cn.kgc.entity.School;
import cn.kgc.service.SchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
public class SchoolController {
    @Autowired
    private SchoolService schoolService;

    @GetMapping("/getAllSchool")
    public HashMap<String,Object> getAllStudent(@RequestParam(value = "page",defaultValue = "1")Integer page,
                                      @RequestParam(value = "limit",defaultValue = "5")Integer limit,
                                     String schoolName){
        int p=(page-1)*limit;
        List<School>list=schoolService.getAllSchool(p,limit,schoolName);
        HashMap<String,Object>map=new HashMap<String, Object>();

        Integer row=schoolService.getCount();
        //响应的状态码
        map.put("code","0");
        //返回的数据
        map.put("data",list);
        map.put("msg","");
        map.put("count",row);

        return map;
    }

    @RequestMapping("/addSchool")
    public Integer addSchool(School school){
        Integer row=schoolService.addSchool(school);
        return row;
    }
    @RequestMapping("updateStudentJson")
    public Integer updateStudentJson(School school){
        Integer row=schoolService.updateStudentJson(school);
        return row;
    }

    @RequestMapping("deleteStudents")
    public Integer deleteStudents(Integer schId){
        Integer row=schoolService.deleteStudents(schId);
        return row;
    }

    @RequestMapping("delSchools")
    public Integer delSchools(String schId){
        Integer row=schoolService.delSchools(schId);
        return row;
    }

    public static void main(String[] args) {
        System.out.println(2222);
    }
}
